package com.qf.service.impl;

import com.qf.mapper.LendMapper;
import com.qf.pojo.Lend;
import com.qf.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class LendServiceImpl implements LendService {
    @Autowired
    private LendMapper lendMapper;
    /**
     * 查询借出/归还信息
     * @return
     */
    @Override
    public List<Lend> findAll() {
        return lendMapper.findAll();
    }

    /**
     * 删除记录
     * @param serNum
     */
    @Override
    public void delete(Long serNum) {
        lendMapper.delete(serNum);
    }
    /**
     * 通过id查询借阅情况
     * @return
     */
    @Override
    public List<Lend> findByReaderId(Long readerId) {
        return lendMapper.findByReaderId(readerId);
    }

    /**
     * 借书记录
     * @param bookId
     * @param readerId
     */
    @Override
    public void insert(Long bookId, Long readerId) {
        Lend lend = new Lend();
        lend.setBookId(bookId);
        lend.setReaderId(readerId);
        lend.setLendDate(new Date());
        lendMapper.insert(lend);
    }
}
